<div style="color:Black;background-color:White;"><pre>
<span style="color:Green;">// cs_keyword_as.cs</span>
<span style="color:Green;">// The as operator</span>
<span style="color:Blue;">using</span> System;
<span style="color:Blue;">class</span> MyClass1
{
}

<span style="color:Blue;">class</span> MyClass2
{
}

<span style="color:Blue;">public</span> <span style="color:Blue;">class</span> IsTest
{
    <span style="color:Blue;">public</span> <span style="color:Blue;">static</span> <span style="color:Blue;">void</span> Main()
    {
        <span style="color:Blue;">object</span>[] myObjects = <span style="color:Blue;">new</span> <span style="color:Blue;">object</span>[6]; <span style="color:Green;">/* test comment 1 */</span>
        myObjects[0] = <span style="color:Blue;">new</span> MyClass1();
        myObjects[1] = <span style="color:Blue;">new</span> MyClass2();
        myObjects[2] = <span style="color:#A31515;">&quot;hello&quot;</span>;
        myObjects[3] = 123;
        myObjects[4] = 123.4;
        myObjects[5] = <span style="color:Blue;">null</span>;

        <span style="color:Blue;">for</span> (<span style="color:Blue;">int</span> i = 0; i &lt; myObjects.Length; ++i)
        {<span style="color:Green;">/* loop it */</span>
            <span style="color:Blue;">string</span> s = myObjects[i] <span style="color:Blue;">as</span> <span style="color:Blue;">string</span>;
            Console.Write(<span style="color:#A31515;">&quot;{0}:&quot;</span>, i);
            <span style="color:Blue;">if</span> (s != <span style="color:Blue;">null</span>)
                Console.WriteLine(<span style="color:#A31515;">&quot;'&quot;</span> + s + <span style="color:#A31515;">&quot;'&quot;</span>);
            <span style="color:Blue;">else</span>
                Console.WriteLine(<span style="color:#A31515;">&quot;not a string&quot;</span>);
        }
    }
}
</pre></div>